package com.jyw.custom.huaxi.oa.domain.dto;

import com.jyw.common.constant.ConfigKeyConstant;
import com.jyw.common.core.domain.entity.SysUser;
import com.jyw.common.utils.SecurityUtils;
import com.jyw.common.utils.spring.SpringUtils;
import com.jyw.system.service.ISysConfigService;
import com.jyw.system.service.ISysUserService;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import org.springframework.util.ObjectUtils;

import javax.xml.bind.annotation.*;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@XmlRootElement(name = "Request")
@XmlAccessorType(XmlAccessType.PROPERTY)
public class HuaxiUserPushDto {
    private Header header;
    private Body body;

    @XmlElement(name = "Header")
    public Header getHeader() {
        return header;
    }
    @XmlElement(name = "Body")
    public Body getBody() {
        return body;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @XmlRootElement(name = "Header")
    @XmlAccessorType(XmlAccessType.PROPERTY)
    public static class Header {
        private String sourceSystem;
        private String messageID;
        @XmlElement(name = "SourceSystem")
        public String getSourceSystem() {
            return sourceSystem;
        }
        @XmlElement(name = "MessageID")
        public String getMessageID() {
            return messageID;
        }
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @XmlRootElement(name = "Body")
    @XmlAccessorType(XmlAccessType.PROPERTY)
    public static class Body {

        private List<CTCareProv> ctCareProvList;

        @XmlElement(name = "CT_CareProv")
        @XmlElementWrapper(name = "CT_CareProvList")
        public List<CTCareProv> getCtCareProvList() {
            return ctCareProvList;
        }
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @XmlRootElement(name = "CT_CareProv")
    @XmlAccessorType(XmlAccessType.PROPERTY)
    public static class CTCareProv {


        private String businessFieldCode;


        private String ctcpAdminiPosition;


        private String ctcpArrivalHosDate;


        private String ctcpBirthDate;


        private String ctcpBirthPlace;


        private String ctcpCareProvPositionCode;


        private String ctcpCareProvTypeCode;


        private String ctcpCode;


        private String ctcpCodesystemCode;


        private String ctcpCreatDate;


        private String ctcpCreatTime;


        private String ctcpCurrDeptDate;


        private String ctcpDeptCode;


        private String ctcpDeptHierarchyCode;


        private String ctcpDesc;


        private String ctcpDurationHospital;


        private String ctcpEducationCode;


        private String ctcpEmail;


        private String ctcpEmploymentDate;


        private String ctcpEndDate;


        private String ctcpExtranetURL;


        private String ctcpHISStopUsingFlag;


        private String ctcpHosCode;


        private String ctcpIDCardNO;


        private String ctcpIDCardTypeCode;


        private String ctcpImageInfo;


        private String ctcpIntranetURL;


        private String ctcpJobNumber;


        private String ctcpName;


        private String ctcpNationCode;


        private String ctcpNativePlace;


        private String ctcpOriginalCode;


        private String ctcpOriginalDesc;


        private String ctcpPassWord;


        private String ctcpPlacement;


        private String ctcpPoliticalAffiliation;


        private String ctcpPoliticalJoinDate;


        private String ctcpPositionSeqCode;


        private String ctcpPositionStatus;


        private String ctcpPracCertiCode;


        private String ctcpQualiCertiCode;


        private String ctcpRegistResidence;


        private String ctcpRemarks;


        private String ctcpRetireDate;


        private String ctcpSexCode;


        private String ctcpSpecialCareFlag;


        private String ctcpSpecialUserFlag;


        private String ctcpSpell;


        private String ctcpStaffCat;


        private String ctcpStaffTypeCode;


        private String ctcpStartDate;


        private String ctcpStatus;


        private String ctcpTelephone;


        private String ctcpTitleEmployDate;


        private String ctcpTitleOfTechCode;


        private String ctcpTitleOfTechLevel;


        private String ctcpUpdateDate;


        private String ctcpUpdateTime;


        private String ctcpUpdateUserCode;


        private String ctcpUrbanRegiResiFlag;


        private String system;


        private String ctcpFirstCode;
        @XmlElement(name = "BusinessFieldCode")
        public String getBusinessFieldCode() {
            return businessFieldCode;
        }
        @XmlElement(name = "CTCP_AdminiPosition")
        public String getCtcpAdminiPosition() {
            return ctcpAdminiPosition;
        }
        @XmlElement(name = "CTCP_ArrivalHosDate")
        public String getCtcpArrivalHosDate() {
            return ctcpArrivalHosDate;
        }
        @XmlElement(name = "CTCP_BirthDate")
        public String getCtcpBirthDate() {
            return ctcpBirthDate;
        }
        @XmlElement(name = "CTCP_BirthPlace")
        public String getCtcpBirthPlace() {
            return ctcpBirthPlace;
        }
        @XmlElement(name = "CTCP_CareProvPositionCode")
        public String getCtcpCareProvPositionCode() {
            return ctcpCareProvPositionCode;
        }
        @XmlElement(name = "CTCP_CareProvTypeCode")
        public String getCtcpCareProvTypeCode() {
            return ctcpCareProvTypeCode;
        }
        @XmlElement(name = "CTCP_Code")
        public String getCtcpCode() {
            return ctcpCode;
        }
        @XmlElement(name = "CTCP_CodesystemCode")
        public String getCtcpCodesystemCode() {
            return ctcpCodesystemCode;
        }
        @XmlElement(name = "CTCP_CreatDate")
        public String getCtcpCreatDate() {
            return ctcpCreatDate;
        }
        @XmlElement(name = "CTCP_CreatTime")
        public String getCtcpCreatTime() {
            return ctcpCreatTime;
        }
        @XmlElement(name = "CTCP_CurrDeptDate")
        public String getCtcpCurrDeptDate() {
            return ctcpCurrDeptDate;
        }
        @XmlElement(name = "CTCP_DeptCode")
        public String getCtcpDeptCode() {
            return ctcpDeptCode;
        }
        @XmlElement(name = "CTCP_DeptHierarchyCode")
        public String getCtcpDeptHierarchyCode() {
            return ctcpDeptHierarchyCode;
        }
        @XmlElement(name = "CTCP_Desc")
        public String getCtcpDesc() {
            return ctcpDesc;
        }
        @XmlElement(name = "CTCP_DurationHospital")
        public String getCtcpDurationHospital() {
            return ctcpDurationHospital;
        }
        @XmlElement(name = "CTCP_EducationCode")
        public String getCtcpEducationCode() {
            return ctcpEducationCode;
        }
        @XmlElement(name = "CTCP_Email")
        public String getCtcpEmail() {
            return ctcpEmail;
        }
        @XmlElement(name = "CTCP_EmploymentDate")
        public String getCtcpEmploymentDate() {
            return ctcpEmploymentDate;
        }
        @XmlElement(name = "CTCP_EndDate")
        public String getCtcpEndDate() {
            return ctcpEndDate;
        }
        @XmlElement(name = "CTCP_ExtranetURL")
        public String getCtcpExtranetURL() {
            return ctcpExtranetURL;
        }
        @XmlElement(name = "CTCP_HISStopUsingFlag")
        public String getCtcpHISStopUsingFlag() {
            return ctcpHISStopUsingFlag;
        }
        @XmlElement(name = "CTCP_HosCode")
        public String getCtcpHosCode() {
            return ctcpHosCode;
        }
        @XmlElement(name = "CTCP_IDCardNO")
        public String getCtcpIDCardNO() {
            return ctcpIDCardNO;
        }
        @XmlElement(name = "CTCP_IDCardTypeCode")
        public String getCtcpIDCardTypeCode() {
            return ctcpIDCardTypeCode;
        }
        @XmlElement(name = "CTCP_ImageInfo")
        public String getCtcpImageInfo() {
            return ctcpImageInfo;
        }
        @XmlElement(name = "CTCP_IntranetURL")
        public String getCtcpIntranetURL() {
            return ctcpIntranetURL;
        }
        @XmlElement(name = "CTCP_JobNumber")
        public String getCtcpJobNumber() {
            return ctcpJobNumber;
        }
        @XmlElement(name = "CTCP_Name")
        public String getCtcpName() {
            return ctcpName;
        }
        @XmlElement(name = "CTCP_NationCode")
        public String getCtcpNationCode() {
            return ctcpNationCode;
        }
        @XmlElement(name = "CTCP_NativePlace")
        public String getCtcpNativePlace() {
            return ctcpNativePlace;
        }
        @XmlElement(name = "CTCP_OriginalCode")
        public String getCtcpOriginalCode() {
            return ctcpOriginalCode;
        }
        @XmlElement(name = "CTCP_OriginalDesc")
        public String getCtcpOriginalDesc() {
            return ctcpOriginalDesc;
        }
        @XmlElement(name = "CTCP_PassWord")
        public String getCtcpPassWord() {
            return ctcpPassWord;
        }
        @XmlElement(name = "CTCP_Placement")
        public String getCtcpPlacement() {
            return ctcpPlacement;
        }
        @XmlElement(name = "CTCP_PoliticalAffiliation")
        public String getCtcpPoliticalAffiliation() {
            return ctcpPoliticalAffiliation;
        }
        @XmlElement(name = "CTCP_PoliticalJoinDate")
        public String getCtcpPoliticalJoinDate() {
            return ctcpPoliticalJoinDate;
        }
        @XmlElement(name = "CTCP_PositionSeqCode")
        public String getCtcpPositionSeqCode() {
            return ctcpPositionSeqCode;
        }
        @XmlElement(name = "CTCP_PositionStatus")
        public String getCtcpPositionStatus() {
            return ctcpPositionStatus;
        }
        @XmlElement(name = "CTCP_PracCertiCode")
        public String getCtcpPracCertiCode() {
            return ctcpPracCertiCode;
        }
        @XmlElement(name = "CTCP_QualiCertiCode")
        public String getCtcpQualiCertiCode() {
            return ctcpQualiCertiCode;
        }
        @XmlElement(name = "CTCP_RegistResidence")
        public String getCtcpRegistResidence() {
            return ctcpRegistResidence;
        }
        @XmlElement(name = "CTCP_Remarks")
        public String getCtcpRemarks() {
            return ctcpRemarks;
        }
        @XmlElement(name = "CTCP_RetireDate")
        public String getCtcpRetireDate() {
            return ctcpRetireDate;
        }
        @XmlElement(name = "CTCP_SexCode")
        public String getCtcpSexCode() {
            return ctcpSexCode;
        }
        @XmlElement(name = "CTCP_SpecialCareFlag")
        public String getCtcpSpecialCareFlag() {
            return ctcpSpecialCareFlag;
        }
        @XmlElement(name = "CTCP_SpecialUserFlag")
        public String getCtcpSpecialUserFlag() {
            return ctcpSpecialUserFlag;
        }
        @XmlElement(name = "CTCP_Spell")
        public String getCtcpSpell() {
            return ctcpSpell;
        }
        @XmlElement(name = "CTCP_StaffCat")
        public String getCtcpStaffCat() {
            return ctcpStaffCat;
        }
        @XmlElement(name = "CTCP_StaffTypeCode")
        public String getCtcpStaffTypeCode() {
            return ctcpStaffTypeCode;
        }
        @XmlElement(name = "CTCP_StartDate")
        public String getCtcpStartDate() {
            return ctcpStartDate;
        }
        @XmlElement(name = "CTCP_Status")
        public String getCtcpStatus() {
            return ctcpStatus;
        }
        @XmlElement(name = "CTCP_Telephone")
        public String getCtcpTelephone() {
            return ctcpTelephone;
        }
        @XmlElement(name = "CTCP_TitleEmployDate")
        public String getCtcpTitleEmployDate() {
            return ctcpTitleEmployDate;
        }
        @XmlElement(name = "CTCP_TitleOfTechCode")
        public String getCtcpTitleOfTechCode() {
            return ctcpTitleOfTechCode;
        }
        @XmlElement(name = "CTCP_TitleOfTechLevel")
        public String getCtcpTitleOfTechLevel() {
            return ctcpTitleOfTechLevel;
        }
        @XmlElement(name = "CTCP_UpdateDate")
        public String getCtcpUpdateDate() {
            return ctcpUpdateDate;
        }
        @XmlElement(name = "CTCP_UpdateTime")
        public String getCtcpUpdateTime() {
            return ctcpUpdateTime;
        }
        @XmlElement(name = "CTCP_UpdateUserCode")
        public String getCtcpUpdateUserCode() {
            return ctcpUpdateUserCode;
        }
        @XmlElement(name = "CTCP_UrbanRegiResiFlag")
        public String getCtcpUrbanRegiResiFlag() {
            return ctcpUrbanRegiResiFlag;
        }
        @XmlElement(name = "system")
        public String getSystem() {
            return system;
        }
        @XmlElement(name = "CTCP_FirstCode")
        public String getCtcpFirstCode() {
            return ctcpFirstCode;
        }

        public SysUser buildUser(){
            ISysUserService userService = SpringUtils.getBean(ISysUserService.class);
            SysUser userDatabase = userService.lambdaQuery().eq(SysUser::getUserName, getCtcpCode()).one();
            SysUser user = new SysUser();
            if (!ObjectUtils.isEmpty(userDatabase)) {
                user.setUserId(userDatabase.getUserId());
            }else{
                ISysConfigService configService = SpringUtils.getBean(ISysConfigService.class);
                //密码加密
                user.setPassword(SecurityUtils.encryptPassword(configService.selectConfigByKey(ConfigKeyConstant.SYS_USER_INIT_PASSWORD)));
            }
            user.setUserName(getCtcpCode());
            user.setNickName(getCtcpName());
            user.setEmail(getCtcpEmail());
            user.setPhonenumber(getCtcpTelephone());
            //性别
            switch (getCtcpSexCode()){
                case "0":
                    user.setSex("2");
                    break;
                case "1":
                    user.setSex("0");
                    break;
                case "2":
                    user.setSex("1");
                    break;
            }

            /**
             * 状态
             * CTCP_Status 启停状态    专指数据的状态（1启用，0停用，-1删除）；还有一个岗位状态字段，一般由订阅方自行判断
             */
            switch (getCtcpStatus()){
                case "-1":
                    user.setDelFlag("2");
                    break;
                case "0":
                    user.setStatus("1");
                    break;
                case "1":
                    user.setStatus("0");
                    user.setDelFlag("0");
                    break;
            }
            return user;
        }


        // ... add more fields as necessary
    }

}